package com.isoft.farm.common.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Aspect
@Component
public class SysCacheAspect {
    private Map<Object,Object> cache=new ConcurrentHashMap<>();
    @Pointcut("@annotation(com.isoft.farm.common.annotation.RequiredCache)")
    public void soCachePointcut(){}

//    @AfterReturning("soCachePointcut()")
//    public void doAfterReturning(){
//
//    }
    @Around("soCachePointcut()")
    public Object doCacheAround(ProceedingJoinPoint joinPoint)throws Throwable{
        System.out.println("Get Data From cache");
        Object obj=cache.get("menuZTree");
        if(obj!=null)return obj;
        System.out.println("Put Data From cache");
        Object result=joinPoint.proceed();
        cache.put("menuZTree",result);
        return null;
    }
}
